def squarechain(n):
	return sum(map(lambda x:x*x, map(int, str(n))))

chainsize = {1:1, 89:89}

def chain(n) :
	try :
		return chainsize[n]
	except KeyError :
		chainsize[n] = chain(squarechain(n))
		return chainsize[n]

_1s = []
for i in range(1, 1e7) :
	if chain(i) == 89 :
		if ()
		print i
		_89s.append(i)
print "== :", len(_89s)
